package com.baosight.sczx.zm.ct.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.zm.ct.domain.ZMCTPerson;
import com.baosight.sczx.zm.ct.domain.ZMCTSmsModelPerson;

/**
 * 
 * <p>Title: ServiceZMCT22.java</p>
 * <p>Description: 发送人员管理</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author wangkun
 * @version 1.0
 * <pre>Histroy:
 *          2012-6-29 上午10:35:06  wangkun  Create
 *</pre>
 */
public class ServiceZMCT22 extends ServiceEPBase 
{
	public EiInfo initLoad(EiInfo inInfo)
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		return this.query(inInfo);
	}
	
	public EiInfo query(EiInfo inInfo)
	{
		StaticTools.setQueryParameters(inInfo, "fdModelId", inInfo.get("fdModelId"), true);//添加查询条件
		EiInfo outInfo = super.query(inInfo, "ZMCTSmsModelPerson.query", new ZMCTSmsModelPerson());
		
		return outInfo;
	}
	
	public EiInfo insert(EiInfo inInfo) 
	{
		String fdModelId = inInfo.get("fdModelId").toString();
		for(int i=0; i<inInfo.getBlock("result").getRowCount(); i++)
		{
			inInfo.getBlock("result").setCell(i, "fdKeyId", TablePk.getInstance().getNextValue("T_CT_SMS_MODEL_PERSON"));//主键
			inInfo.getBlock("result").setCell(i, "fdModelId", fdModelId);//外键
			inInfo.getBlock("result").setCell(i, "fdPersonNo", inInfo.getBlock("result").getCell(i, "fdNo"));//工号
			inInfo.getBlock("result").setCell(i, "fdPersonName", inInfo.getBlock("result").getCell(i, "fdName"));//姓名
		}
		
		EiInfo _temp = super.insert(inInfo, "ZMCTSmsModelPerson.insert");
		
		EiInfo outInfo = this.query(inInfo);
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
	
	public EiInfo delete(EiInfo inInfo) 
	{
		EiInfo _temp = super.delete(inInfo, "ZMCTSmsModelPerson.delete");
		
		EiInfo outInfo = this.query(inInfo);
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
	
	/**
	 * 
	 * <p>Function: queryPerson</p>
	 * <p>Description: 提供插入窗口人员信息，不包含已插入记录</p>
	 * <p>return value:EiInfo</p>
	 * <p>History:
	 *    2012-6-29上午10:35:38 wangkun
	 * </p>
	 *
	 */
	public EiInfo queryPerson(EiInfo inInfo)
	{
		String fdModelId = inInfo.get("fdModelId").toString();
		Map inMap = new HashMap();
		inMap.put("fdModelId", fdModelId);
		List _list = dao.query("ZMCTSmsModelPerson.query", inMap);
		String fdNotInNo = "(";
		for(int i=0; i<_list.size(); i++)
		{
			if(i != 0)
			{
				fdNotInNo += ",";
			}
			ZMCTSmsModelPerson person = (ZMCTSmsModelPerson)_list.get(i);
			fdNotInNo += "'" + person.getFdPersonNo()+"'";
		}
		fdNotInNo += ")";
		
		if(!fdNotInNo.equals("()"))
		{
			StaticTools.setQueryParameters(inInfo, "fdNotInNo", fdNotInNo, true);//添加查询条件
		}
		
		StaticTools.setQueryParameters(inInfo, "fdMobilePhoneNotNull", "true", true);
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = super.query(inInfo, "ZMCTPerson.queryPerson", new ZMCTPerson());
		
		return outInfo;
	}
}
